package com.cuit.riskassessment.action.rb;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cuit.riskassessment.service.RbService;
import com.cuit.riskassessment.util.Result;
import com.cuit.riskassessment.vo.Rb;

@Controller
@RequestMapping(value = "rb")
public class RbAction {
	@Autowired
	@Resource(name = "rbService")
	private RbService rbService;
/**
 * 修改或添加rb
 * @param res
 * @param rb
 * @return
 */
	@RequestMapping(value = "addRb")
	public @ResponseBody
	Object addRb(HttpServletResponse res, Rb rb,@RequestParam(value="projid") Integer projid) {
		res.setHeader("Accept", "application/json");
		Result result = new Result();
		rb.setPid(projid);
		if (this.rbService.addRb(rb)) {
			result.setMessage("操作成功");
			result.setSuccess(false);
		} else {
			result.setMessage("操作失败！");
			result.setSuccess(false);
		}

		return result;
	}
	/**
	 * 获取数据库Rb的值注入前台表单
	 * @param res
	 * @param projid
	 * @return Json
	 */
	@RequestMapping(value = "setRb")
	public @ResponseBody Object setRb(HttpServletResponse res,@RequestParam(value="projid")int projid){
		Result result = new Result();
		res.setHeader("Accept", "application/json");
		Object obj = rbService.setRb(projid);
		if (obj==null) {
			result.setSuccess(false);
		}else {
			result.setSuccess(true);
			result.setOthers(obj);
		}
		return result;
	}
}
